<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>设置日志的可用事件</title>
  </head>
  <body>
    <script>
      /**
       * console.log 方法重写
       * 
       * 判断配置文件是否开启日志调试 是否输出日志 True 输出 False 不输出
       */
      console.log = (function (oriLogFunc) {
        return function () {
         const time = new Date().getTime();
          // 是否显示log输出
         const logDebug = Number(localStorage.getItem('log')) >= time;
          if (logDebug) {
            oriLogFunc.apply(this, arguments);
          }
        };
      })(console.log);

      window.__debugger = () => {
        // 有效期一分钟
        const time = new Date().getTime() + 1000 * 60;
        localStorage.setItem('log', time);
      }


      console.log("12312");

      function disablelog(){
        console.log('后续不再打印log');
        localStorage.removeItem('log')
      }
      function oonclick(){
        console.log(12313);
        debugger
        const logDebug = Number(localStorage.getItem('log'))
        const time = new Date().getTime();
        const ad = parseInt((logDebug - time) / 1000) + 10000;
        console.log(`未超时，可输出 ${ad}s 后过期`);
      }
    </script>
    <div onclick="disablelog()">关闭log输出</div>
    <div onclick="__debugger()">开启log输出</div>
    <div onclick="oonclick()">点击输出</div>
  </body>
</html>
